package tech.edwardvan.cloudapib.factory;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import tech.edwardvan.cloudapib.client.CloudBClient;
import tech.edwardvan.cloudapib.entity.Message;
import tech.edwardvan.cloudcommon.entity.ServerResponse;

/**
 * 熔断配置类
 *
 * @author EdwardVan
 */
@Slf4j
public class CloudBClientFallbackFactory implements FallbackFactory<CloudBClient> {

    @Override
    public CloudBClient create(Throwable cause) {
        return new CloudBClient() {
            @Override
            public ServerResponse<Message> receive(Message message) {
                log.error(cause.getMessage());
                return ServerResponse.errorMessage("cloud-b服务不可用!");
            }
        };
    }
}
